package com.sunwayhorizo.health.business.dto;

public class PageDTO {
	/**
	 * 是否有上一页
	 */
	private boolean hasPrePage;

	/**
	 * 是否有下一页
	 */
	private boolean hasNextPage;

	/**
	 * 每页数据量
	 */
	private int pageSize = 25;

	/**
	 * 总页数
	 */
	private int totalPage = 1;

	/**
	 * 第几页
	 */
	private int pageNo = 1;

	/**
	 * 开始数据数
	 */
	private int beginIndex = 0;

	/**
	 * 总数据数
	 */
	private int totalRecord = 0;

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public PageDTO() {

	}

	public PageDTO(boolean hasPrePage, boolean hasNextPage, int pageSize,
			int totalPage, int pageNo, int beginIndex, int totalRecord) {
		super();
		this.hasPrePage = hasPrePage;
		this.hasNextPage = hasNextPage;
		this.pageSize = pageSize;
		this.totalPage = totalPage;
		this.pageNo = pageNo;
		this.beginIndex = beginIndex;
		this.totalRecord = totalRecord;
	}

	public PageDTO(int pageSize) {
		super();
		this.pageSize = pageSize;
	}

	public int getBeginIndex(int everyPage, int currentPage) {
		return (currentPage - 1) * everyPage;
	}

	public int getTotalPage(int everyPage, int totalRecords) {
		int totalPage = 0;
		if (totalRecords % everyPage == 0)
			totalPage = totalRecords / everyPage;
		else
			totalPage = totalRecords / everyPage + 1;
		return totalPage;
	}

	public boolean hasPrePage(int currentPage) {
		return currentPage == 1 ? false : true;
	}

	public boolean hasNextPage(int currentPage, int totalPage) {
		return currentPage == totalPage || totalPage == 0 ? false : true;
	}

	public boolean isHasPrePage() {
		return hasPrePage;
	}

	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getPageNo() {
		if(pageNo<1){
			return 1;
		}
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getBeginIndex() {
		if(beginIndex<0){
			return 0;
		}
		return beginIndex;
	}

	public void setBeginIndex(int beginIndex) {
		this.beginIndex = beginIndex;
	}

}
